using Microsoft.EntityFrameworkCore;
using System.Reflection;
using WorkOrder.Infastructure.Impelment;
using WorkOrder.Infastructure.Interface;
using WorkOrder.Infastructure;
using WorkOrder.Api.Read;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(x =>
{
    var file = AppContext.BaseDirectory + @"WorkOrder.Api.Write.xml";
});
builder.Services.AddScoped(typeof(IBaseRepository<>), typeof(BaseRepository<>));

builder.Services.AddDbContext<MyDbContext>(x =>
{
    x.UseSqlServer(builder.Configuration.GetConnectionString("conn"));
});
builder.Services.AddMediatR(x =>
{
    x.RegisterServicesFromAssemblies(Assembly.GetEntryAssembly());
});
builder.Services.AddAutoMapper(typeof(MapperProFile));
builder.Services.AddCors(x =>
{
    x.AddPolicy("2211A", policy =>
    {
        policy.WithOrigins("http://localhost:5026").AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin();
    });
});
var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}
app.UseCors("2211A");
app.UseAuthorization();

app.MapControllers();

app.Run();
